//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@geopainting.com), 2002-2006
//
// GPS position cursor drawing.
//

# include "StdAfx.h"
# include "PosCursor.h"
# include "Scale.h"
# include "Position.h"
# include "Positioning.h"
# include "fast_floor.h"
# include "Globals.h"

void ShowPosCursor (HDC _hDC) {
	const PositionInfo_t pi = GetPositionInfo ();

	const long x0 = XToScreen (pi.fX);
	const long y0 = YToScreen (pi.fY);

	const float fA = (pi.dwDef & PositionInfo_t::defAzimuth) ? pi.fAzimuth*c_PI/180.f : 0;
	const float fCosA = ::cos (fA);
	const float fSinA = ::sin (fA);

	const size_t c_cH1 = 9;//3;
	const size_t c_cH2 = 24;//8;

	POINT pts [3];
	pts [0].x = x0 + ::fast_floor (c_cH1*fCosA + .5f);
	pts [0].y = y0 + ::fast_floor (c_cH1*fSinA + .5f);
	pts [1].x = x0 - ::fast_floor (c_cH1*fCosA + .5f);
	pts [1].y = y0 - ::fast_floor (c_cH1*fSinA + .5f);
	pts [2].x = x0 + ::fast_floor (c_cH2*fSinA + .5f);
	pts [2].y = y0 - ::fast_floor (c_cH2*fCosA + .5f);

	::SelectObject (_hDC, ::GetStockObject (BLACK_BRUSH));
	::SelectObject (_hDC, ::GetStockObject (WHITE_PEN));
	::Polygon (_hDC, pts, 3);

	if (pi.dwDef & PositionInfo_t::defXYPrec) {
		const long r = g_fScale > 0 ? ::fast_floor (pi.fXYPrec/g_fScale) : 0;
		if (r > c_cH2) {
			::SelectObject (_hDC, ::GetStockObject (NULL_BRUSH));
			::Ellipse (_hDC, x0 - r, y0 - r, x0 + r, y0 + r);
		}
	}
}
